<?php 

function monthfirstday($num){
	date_default_timezone_set("PRC");
	$currentTime = time();
	$cyear = floor(date("Y",$currentTime));
	$cMonth = floor(date("m",$currentTime));
	for($i=0;$i<$num;$i++){
	$nMonth = $cMonth-$i;
	$cyear = $nMonth == 0 ? ($cyear-1) : $cyear;
	$nMonth = $nMonth <= 0 ? 12+$nMonth : $nMonth;
	$date = $cyear."-".$nMonth."-1";
	$firstday = date('01', strtotime($date));
	$lastday = date('t', strtotime($date));

	// echo $cyear."年".$nMonth."月";
	// echo "第一天:".$firstday;
	// echo "最后一天:".$lastday,"";
}
	echo 	$cyear.'-'.$nMonth.'-'.$firstday;


}
function monthlastday($num){
	date_default_timezone_set("PRC");
	$currentTime = time();
	$cyear = floor(date("Y",$currentTime));
	$cMonth = floor(date("m",$currentTime));
	for($i=0;$i<$num;$i++){
	$nMonth = $cMonth-$i;
	$cyear = $nMonth == 0 ? ($cyear-1) : $cyear;
	$nMonth = $nMonth <= 0 ? 12+$nMonth : $nMonth;
	$date = $cyear."-".$nMonth."-1";
	$firstday = date('01', strtotime($date));
	$lastday = date('t', strtotime($date));

	// echo $cyear."年".$nMonth."月";
	// echo "第一天:".$firstday;
	// echo "最后一天:".$lastday,"";
}
	echo 	$cyear.'-'.$nMonth.'-'.$lastday;


}


monthfirstday(1);








 ?>